﻿// Keep user from entering more than maxLength characters
function doKeypress(e, TextBox) {
    maxLength = TextBox.attributes["maxLength"].value;
    value = TextBox.value;
    if (maxLength && value.length > maxLength - 1) {
        alert('Please limit message to ' + maxLength + ' characters.') 
        if (window.event) { // IE
            event.returnValue = false;
        } else { // FF
            e.preventDefault();
        }
        maxLength = parseInt(maxLength);
    }
}
// Cancel default behavior
function doBeforePaste(e, TextBox) {
    maxLength = TextBox.attributes["maxLength"].value;
    if (maxLength) {
        alert('Please limit message to ' + maxLength + ' characters.') 
        if (window.event) { // IE
            event.returnValue = false;
        } else { // FF
            e.preventDefault();
        }
    }
}
// Cancel default behavior and create a new paste routine
function doPaste(e, TextBox) {
    maxLength = TextBox.attributes["maxLength"].value;
    value = TextBox.value;
    if (maxLength) {
        alert('Please limit message to ' + maxLength + ' characters.') 
        if (window.event) { // IE
            event.returnValue = false;
        } else { // FF
            e.preventDefault();
        }
        maxLength = parseInt(maxLength);
        var oTR = TextBox.document.selection.createRange();
        var iInsertLength = maxLength - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}